package site.icesky.springboot.log;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@SpringBootApplication
@RestController
public class SpringLog2Application {
    private static final Logger logger = LoggerFactory.getLogger(SpringLog2Application.class);

    public static void main(String[] args) {
        SpringApplication.run(SpringLog2Application.class,
                    "--spring.application.name=SpringLog2",
                "--server.port=9000");
    }

    @RequestMapping("/api")
    public String printDate(@RequestHeader(name = "user-name", required = false) String username) {

        logger.info("API收到请求" + username);

        if (username != null) {
            return new Date().toString() + " " + username;
        }
        return new Date().toString();
    }


}
